package com.zhida.smartcontrol.dialog.kzqlistdialog;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.common.bean.LampBean;
import com.zhida.smartcontrol.dialog.grouplistdialog.GroupListDialogContract;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.List;

public class KzqListDialogPresenter extends BasePresenterImpl<KzqListDialogContract.View> implements KzqListDialogContract.Presenter{
    @Override
    public void requestKzqList(String groupId, boolean showLoading) {
        if (TextUtils.isEmpty(groupId)) {
            return;
        }
        Params params = Params.newBuilder()
                .add("switchType", "0")
                .add("groupId", groupId)
                .build();
        mKalleCenter.get(Api.DEVICE_LIST, params, showLoading, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                List<LampBean> lampBeans = JSON.parseArray(result, LampBean.class);
                mView.showKzq(lampBeans);
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }
}
